﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;

namespace GXJD.WxApp.Pages
{
    using Microsoft.AspNetCore.Cors;
    using Microsoft.Extensions.Options;
    using Models;

    [EnableCors("any")]
    [IgnoreAntiforgeryToken(Order = 1001)]
    public class onLoginModel : PageModel
    {
        //private readonly ILogger<onLoginModel> _logger;

        public void OnGet(
            [FromServices]ILogger<onLoginModel> _logger)
        {
            _logger.LogInformation("onLogin页面打开");
        }

        public IActionResult OnPost(
            [FromServices]ILogger<onLoginModel> _logger,
            [FromServices]IOptions<AppSettings> _mySetting,
            [FromBody]clsOnLoginRequest value)
        {
            _logger.LogInformation("onLogin：" + value);
            _logger.LogInformation("wxAppId：" + _mySetting.Value.wxAppId);
            _logger.LogInformation("wxAppSecret：" + _mySetting.Value.wxAppSecret);

            if (value != null && !string.IsNullOrEmpty(value.code))
            {

                //var _req = Newtonsoft.Json.JsonConvert.DeserializeObject<clsOnLoginRequest>(value);
            }

            return new JsonResult(value);
        }

        #region 小程序登录用到的类定义

        /// <summary>
        /// 登录注册的请求类
        /// </summary>
        public class clsOnLoginRequest
        {
            public string code { get; set; }

            public clsOnLoginRequest()
            {

            }
        }

        #endregion
    }
}